import axios from './index'

const preUrl = ''


// 查询业务员列表
const getSalesmanList = {
  p: [`get,/salesman/*/select/**`],
  r: params => {
    axios.defaults.headers.permission = `get,/salesman/*/select/**`
    return axios.get(`${preUrl}/salesman/${Cookie.get('areaCode')}/select`, {
      params
    })
  }
}

// 添加业务员
const addSalesman = {
  p: [`post,/salesman/*/create`],
  r: params => {
    axios.defaults.headers.permission = `post,/salesman/*/create`
    return axios.post(`${preUrl}/salesman/${Cookie.get('areaCode')}/create`, params)
  }
}

// 删除业务员
const deleteSalesman = {
  p: [`put,/salesman/*/valid`],
  r: params => {
    axios.defaults.headers.permission = `put,/salesman/*/valid`
    axios.defaults.headers['Authorization'] = Cookie.get('token');
    return axios.put(`${preUrl}/salesman/${Cookie.get('areaCode')}/valid`, params)
  }
}

// 编辑业务员信息
const editSalesman = {
  p: [`put,/salesman/*`],
  r: params => {
    axios.defaults.headers.permission = `put,/salesman/*`
    axios.defaults.headers['Authorization'] = Cookie.get('token');
    return axios.put(`${preUrl}/salesman/${Cookie.get('areaCode')}`, params)
  }
}

// 获取业务员业绩
const getPerformance = {
  p: [`get,/salesman/*/grade/**`],
  r: params => {
    axios.defaults.headers.permission = `get,/salesman/*/grade/**`
    return axios.get(`${preUrl}/salesman/${Cookie.get('areaCode')}/grade`, {
      params
    })
  }
}

// 更改业务员等级
const changeLevel = {
  p: [`put,/salesman/*/level`],
  r: params => {
    axios.defaults.headers.permission = `put,/salesman/*/level`
    axios.defaults.headers['Authorization'] = Cookie.get('token');
    return axios.put(`${preUrl}/salesman/${Cookie.get('areaCode')}/level`, params)
  }
}

// 获取业务员详情
const getDetails = {
  p: [`get,/salesman/*/*`],
  r: uid => {
    axios.defaults.headers.permission = `get,/salesman/*/*`
    return axios.get(`${preUrl}/salesman/${Cookie.get('areaCode')}/${uid}`)
  }
}

export {
  getSalesmanList,
  addSalesman,
  deleteSalesman,
  editSalesman,
  getPerformance,
  changeLevel,
  getDetails,
}